#ifndef RESOURCE_H
#define RESOURCE_H

#include "../CommunicationModule/Request.h"
#include <map>
#include <unistd.h>
#include <string>
#include <cstdio>

class Resource
{
public:
	Resource(int id, pid_t firstOwner, LockType firstLock);

	bool addOwner(pid_t pid, LockType type);
	
	bool canAddOwner(pid_t pid, LockType type);

	bool removeOwner(pid_t pid);

	pid_t update();

	bool removeWaiting(pid_t pid);

	int getOwnersSize();

	int getWaitingSize();

	std::string getLocksStr();

	std::string getWaitingLocksStr();

private:
	Resource();

	bool excludes(LockType already, LockType candidate);

	std::string getUniLocksStr(std::map<pid_t, LockType>& map);

	unsigned int id_;

	std::map<pid_t, LockType> currentOwners_;

	std::map<pid_t, LockType> waitingProcesses_;
};

#endif
